Skip to content

Conversation

Copy link

Copilot AI commented Jan 5, 2026

The EnsureNamespace function silently ignored errors from GetNamespaces, masking connection/permission issues and potentially causing duplicate namespace creation attempts.

Changes

  • Error flow restructure: Changed if err == nil to if err != nil with explicit handling. When namespace listing fails, proceed to creation (listing may fail due to permissions while creation succeeds). The subsequent CreateNamespace call surfaces genuine errors.

  • Idempotent creation: Detect "already exists" errors from CreateNamespace and treat as success. Uses case-insensitive string matching for multiple error patterns since Pulsar admin client lacks typed errors:

    errMsg := strings.ToLower(err.Error())
    if strings.Contains(errMsg, "already exists") ||
        strings.Contains(errMsg, "alreadyexists") ||
        strings.Contains(errMsg, "409") ||
        strings.Contains(errMsg, "conflict") {
        return nil
    }
  • Error context: Real errors now properly propagate with fmt.Errorf wrapping.

Before: Connection/permission errors during listing were ignored, errors from duplicate creation were returned.

After: Real errors surface appropriately, function is fully idempotent.


💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.

Copilot AI and others added 4 commits January 5, 2026 07:04
- Add explicit handling for GetNamespaces errors with fallback logic
- Handle "already exists" errors gracefully when creating namespaces
- Add strings package import for error message checking
- Improve comments to explain error handling strategy

Co-authored-by: freeznet <[email protected]>
- Add comprehensive comment explaining why string matching is used
- Add "Conflict" to the list of error patterns to check
- Clarify this is a best-effort approach for test utilities

Co-authored-by: freeznet <[email protected]>
- Convert error messages to lowercase for robust pattern matching
- Add comment about using case-insensitive matching
- Ensures error detection works regardless of message casing

Co-authored-by: freeznet <[email protected]>
- Run go fmt to ensure consistent formatting
- Update comment patterns to reflect lowercase matching
- Fix struct field alignment

Co-authored-by: freeznet <[email protected]>
Copilot AI changed the title [WIP] Address feedback on E2E testing implementation fix(testutil): handle GetNamespaces errors in EnsureNamespace Jan 5, 2026
Copilot AI requested a review from freeznet January 5, 2026 07:10
@freeznet freeznet closed this Jan 8, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants